home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / ccas01.arc / _XENIX.ASM next >
Encoding:
Assembly Source File  |  1986-03-15  |  10.0 KB  |  480 lines

  1. title MSDOS 2.00 Function Library for Lattice C
  2. TRUE    EQU    0
  3. FALSE    EQU    -1
  4. ;
  5. ;........................................
  6. ;.                    .
  7. ;.    DOS 2.00 Functions for        .
  8. ;.           Lattice            .
  9. ;.                    .
  10. ;.    T. Jennings 23 June 83        .
  11. ;.      created 13 Sept 82        .
  12. ;.                    .
  13. ;........................................
  14. ;
  15. ;MSDOS 2.00 support for Lattice. These will NOT
  16. ;work for version 1.xx of DOS. All support full
  17. ;paths. The function names are the same as the
  18. ;standard library names with "_x" prepended, to
  19. ;accomodate my file system nameing heirarchy.
  20. ;
  21. ;NOTE: You cannot mix these calls with the 
  22. ;Lattice library calls: i.e. open with _xopen()
  23. ;and write with open(). You must use ALL or
  24. ;NONE.
  25. ;
  26. ;These functions all use the DOS buffers. 
  27. ;
  28. ;Detailed info is given in the title block for
  29. ;each function. A quick description follows.
  30. ;
  31. ;handle= _xopen(pathname,access);
  32. ;int handle,access;
  33. ;char *pathname;
  34. ;
  35. ;    Open a file. handle returns either 
  36. ;the DOS handle, or -1 if error (file not 
  37. ;found). Access is: 0 == read only, 1 == write
  38. ;only, 2 == read/write.
  39. ;
  40. ;handle= _xcreat(pathname,access);
  41. ;
  42. ;    Create a new file, delete any existing
  43. ;copy. Access is not used: use 0. Returns the
  44. ;handle or -1 if error.
  45. ;
  46. ;v= _xread(handle,buffer,count);
  47. ;v= _xwrite(handle,buffer,count);
  48. ;int v,handle,count;
  49. ;char *buffer;
  50. ;
  51. ;    File read or write to an opened or
  52. ;created file. reads or writes 'count' bytes
  53. ;to the file 'handle', to or from 'buffer'.
  54. ;Returns the number of bytes processed: equal
  55. ;to 'count' if sucessful.
  56. ;
  57. ;error= _xclose(handle)
  58. ;int error;
  59. ;
  60. ;    Close an open file. Returns -1 if 
  61. ;error. Any buffers are flushed at this point.
  62. ;
  63. ;_xdelete(pathname);
  64. ;
  65. ;    Remove the file from the file
  66. ;system.
  67. ;
  68. ;fsize= _fsize(pathname);
  69. ;long fsize;
  70. ;
  71. ;    Returns the size of the file in bytes.
  72. ;Returns 0 if no file. Do NOT call inbetween
  73. ;calls to _xfind().
  74. ;
  75. ;found= _xfind(pathname,filename,&fsize,attrib,flag);
  76. ;int found,flag,attrib;
  77. ;char *pathname,filename[14];
  78. ;long fsize;
  79. ;
  80. ;Search for the specified pathname. flag should
  81. ;be 0 for the first call, non-zero for all
  82. ;subsequent calls. _xfind() returns true if a
  83. ;match was found, and the found file is 
  84. ;returned in filename[], in ASCIZ format.
  85. ;Attrib is the DOS attributes to match; I
  86. ;will not describe that mess here. _xfind()
  87. ;returns the size of the file in fsize. (Don't
  88. ;forget to pass the address of fsize.)
  89. ; For example:
  90. ;
  91. ;int i;
  92. ;char filename[14];
  93. ;long fsize;
  94. ;
  95. ;    i= 0;
  96. ;    while (_xfind("\\bin\\*.*",filename,&fsize,0,i)) {
  97. ;        printf("File: %14s Size: %lu\n",filename,fsize);
  98. ;        ++i;
  99. ;    }
  100. ;    printf("%u matching files.\n",i);
  101. ;
  102. ;Prints the names of all matching disk files. 
  103. ;Any other calls (except_fsize()) can be made
  104. ;in between calls to _xfind().
  105. ;
  106. dgroup group data
  107. pgroup group prog
  108.  
  109. prog segment byte public 'prog'
  110.  
  111. public    _xopen,_xcreat,_xclose
  112. public    _xread,_xwrite
  113. public    _xfind,_XLSEEK
  114. public    _xfsize,_XCHMOD,_XEXIT
  115. public     _xdelete,_XUNLINK,_XWAIT,_XGETDIR,_XCHDIR
  116. assume cs:pgroup,ds:dgroup
  117. ;;
  118. ;;    _XLSEEK to a position within the file.
  119. ;;Reminder: The second argument is a long (32bit)
  120. ;;integer and this routine returns a 32bit integer
  121. ;;
  122. ;;    pos = _XLSEEK(handle,offset,mode);
  123. ;;
  124. ;;    long pos;        -1 if error, new file
  125. ;;                position if successful
  126. ;;    int handle;        file handle
  127. ;;    long offset;        desired position
  128. ;;    int mode;        offset mode:
  129. ;;                0 = relative to beginning of file
  130. ;;                1 = relative to current position
  131. ;;                2 = relative to end-of-file
  132. ;;
  133. _XLSEEK    PROC    NEAR
  134.     PUSH    BP
  135.     MOV    BP,SP
  136.     MOV    BX,[BP+4]
  137.     MOV    DX,[BP+6]    ;LSW of offset
  138.     MOV    CX,[BP+8]    ;MSW of offset
  139.     MOV    AX,[BP+10]    ;mode (in AL only)
  140.     MOV    AH,42H
  141.     INT    21H
  142.     JNC    LSKGR
  143.     MOV    AX,FALSE
  144.     MOV    BX,AX
  145.     POP    BP
  146.     RET
  147. LSKGR:    MOV    BX,AX
  148.     MOV    AX,DX
  149.     POP    BP
  150.     RET
  151. _XLSEEK    ENDP
  152. ;;
  153. ;;    ret = _XCHMOD(path,attribute);
  154. ;;
  155. ;;    int ret;        error codes
  156. ;;    char *path;        null terminated drv:\path\filename.ext
  157. ;;    int attribute;        attribute to set file to
  158. ;;
  159. _XCHMOD    PROC    NEAR
  160.     PUSH    BP
  161.     MOV    BP,SP
  162.     MOV    AX,4301H    ;Function 43H, al=01H CX contains attribute
  163.     MOV    DX,[BP+4]
  164.     MOV    CX,[BP+6]
  165.     INT    21H
  166.     MOV    AX,TRUE
  167.     JNC    CHMODGR
  168.     DEC    AX
  169. CHMODGR:POP    BP
  170.     RET
  171. _XCHMOD    ENDP
  172. ;;
  173. ;;    _XEXIT(exitcode);    THE RIGHT WAY TO DO IT.
  174. ;;                SETS ERRORLEVEL = EXITCODE
  175. ;;
  176. ;;    int exitcode;        0 normal exit; otherwise an error occurred
  177. ;;
  178. _XEXIT    PROC    NEAR
  179.     PUSH    BP
  180.     MOV    BP,SP
  181.     MOV    AX,[BP+4]
  182.     MOV    AH,4CH
  183.     INT    21H        ;DOESN'T RETURN...
  184. _XEXIT    ENDP
  185.  
  186. ;;    ret = _XWAIT()        Wait for a child process to terminate
  187. ;;
  188. ;;    int ret;        The return code given from _XEXIT(code)
  189. ;;
  190. _XWAIT    PROC    NEAR
  191.     PUSH    BP
  192.     MOV    BP,SP
  193.     MOV    AH,04DH
  194.     INT    21H        ;Return code(s) in AH,AL
  195.     POP    BP
  196.     RET
  197. _XWAIT    ENDP
  198. ;;
  199. ;;    ret = _XGETDIR(pathname,drive);
  200. ;;
  201. ;;    int ret;        ret = -1 if error
  202. ;;    char pathname;        The returned path name "path\filename.ext\0"
  203. ;;                null terminated and NO leading backslash and
  204. ;;                NO drive letter
  205. ;;    int drive;        The drive to get the current dir of.
  206. ;;                0 = default, 1 = A, etc.
  207. ;;
  208. _XGETDIR PROC    NEAR
  209.     PUSH    BP
  210.     MOV    BP,SP
  211.     MOV    AH,47H
  212.     MOV    SI,[BP+4]
  213.     MOV    DX,[BP+6]
  214.     AND    DX,0FFH
  215.     INT    21H
  216.     JNC    GDRET
  217.     MOV    AX,FALSE
  218. GDRET:    POP    BP
  219.     RET
  220. _XGETDIR ENDP
  221.  
  222. ;;    ret = _XCHDIR(path);
  223. ;;
  224. ;;    int ret;        ret = -1 if error (path not changed)
  225. ;;
  226. ;;    char path;        path to set.  Nul terminated WITH drive
  227. ;;
  228. _XCHDIR    PROC    NEAR
  229.     PUSH    BP
  230.     MOV    BP,SP
  231.     MOV    DX,[BP+4]
  232.     MOV    AH,3BH
  233.     INT    21H
  234.     JNC    CDRET
  235.     MOV    AX,FALSE
  236. CDRET:    POP    BP
  237.     RET
  238. _XCHDIR    ENDP
  239.  
  240. ;;
  241. ;;    handle= _xcreat(name,access)
  242. ;;    handle= _xopen(name,access)
  243. ;;
  244. ;;    int handle;        -1 if error,
  245. ;;    int access;        0=r, 1=w, 2=r/w
  246. ;;    char *name;        null terminated
  247. ;;
  248. ;;Open and create functions. The name is a null
  249. ;;terminated string. The access byte is passed
  250. ;;directly to DOS. All errors are translated to
  251. ;;a -1 return value.
  252. ;;
  253. _xopen proc near
  254.     mov    ah,61
  255.     jmp    short opncrt
  256. _xcreat    proc near
  257.     mov    ah,60
  258.  
  259. opncrt:    push    bp
  260.     mov    bp,sp
  261.     mov    dx,[bp+4]    ;pathname,
  262.     mov    al,[bp+6]    ;access,
  263.     xor    bx,bx
  264.     xor    cx,cx
  265.     int    21h        ;do it,
  266.     jnc    opncrt1
  267.     mov    ax,-1        ;error!
  268. opncrt1:pop    bp
  269.     ret
  270.  
  271. _xcreat    endp
  272. _xopen endp
  273. ;;
  274. ;;_xclose(handle)
  275. ;;int handle;
  276. ;;
  277. ;;Close a handle opened by _XOPEN or _XCREATE.
  278. ;;Returns -1 if close error.
  279. ;;
  280. _xclose proc near
  281.     mov    ah,62
  282.     push    bp
  283.     mov    bp,sp
  284.     mov    bx,[bp+4]    ;handle,
  285.     int    21h
  286.     pop    bp
  287.     ret
  288.  
  289. _xclose endp
  290. page
  291. ;;
  292. ;;    count= _xread(handle,buffer,size)
  293. ;;    count= _xwrite(handle,buffer,size)
  294. ;;
  295. ;;    int count;    bytes actually r/w
  296. ;;    int handle;
  297. ;;    char *buffer;
  298. ;;    int size;    byte count,
  299. ;;
  300. ;;    Read or write (size) bytes from the
  301. ;;file (handle). The return value is the number 
  302. ;;of bytes actually processed.
  303. ;;
  304. ;;    No text translation is done. All
  305. ;;bytes are processed as read or written. No
  306. ;;check is done (or is possible) on the buffer
  307. ;;size.
  308. ;;
  309. ;;    THE ERROR PART RETURNS -1 IF AN ERROR
  310. ;;HAS TAKEN PLACE DURING A _XREAD OR _XWRITE.
  311. ;;TAKEN FROM SIG/86 NEWSLETTER VOL 3 NUMBER 3
  312. ;;BY JOSEPH BOYKIN.
  313. ;;    PLACED HERE BY ALAN MINCHEW 8/24/84.
  314. ;;
  315. _xread proc near
  316.     mov    ah,63
  317.     jmp    short rdwrt
  318. _xwrite proc near
  319.     mov    ah,64
  320.  
  321. rdwrt:    push    bp
  322.     mov    bp,sp
  323.     mov    bx,[bp+4]    ;handle,
  324.     mov    cx,[bp+8]    ;count,
  325.     mov    dx,[bp+6]    ;buffer,
  326.     int    21h
  327.     JNC    RWERR        ;ERROR CHECK PART TAKEN FROM
  328.     MOV    AX,-1        ; XENIX CALLS BY Joe Boykin in SIG/86 V3.N3
  329. RWERR:    pop    bp
  330.     ret
  331.  
  332. _xwrite endp
  333. _xread endp
  334. page
  335. ;;
  336. ;;    ret= xfind(path,name,size,attrib,first)
  337. ;;    int ret;        0 if no match
  338. ;;    char *path;
  339. ;;    char *name;        dest name,
  340. ;;    long *size;        ptr to file siz
  341. ;;    int attrib;        attributes
  342. ;;    int first;        0 if 1st time,
  343. ;;
  344. ;;Find the Nth occurence of pathname. Returns
  345. ;;0 when no match. Only the filename portion
  346. ;;can contain wildcards. The returned filename
  347. ;;does not contain the path portion of the 
  348. ;;input string.
  349. ;;    Not recursive. Do not call _FSIZE
  350. ;;inbetween _XFIND calls.
  351. ;;
  352. xfpath    equ    4    ;path pointer,
  353. xfname    equ    6    ;retnd name,
  354. xfsize    equ    8    ;file size ptr,
  355. xfaccess equ    10    ;access,
  356. xfflag    equ    12    ;first time flag,
  357.  
  358. _xfind proc near
  359.     push    bp
  360.     mov    bp,sp
  361.     mov    ah,26        ;set DMA addr
  362.     mov    dx,offset dgroup:xfbuf
  363.     int    21h        ;to buffer,
  364.     test word ptr [bp+xfflag],-1
  365.     mov    ah,78        ;do right call,
  366.     jz    xf1
  367.     mov    ah,79        ;0 == 1st time,
  368. xf1:    mov    dx,[bp+xfpath]    ;path name,
  369.     mov    cx,[bp+xfaccess];access,
  370.     int    21h
  371.     mov    ax,0        ;ret if no
  372.     jc    xfr        ;match,
  373. ;
  374. ;Copy the file size in.
  375. ;
  376.     mov    bx,[bp+xfsize]    ;size ptr,
  377.     mov    ax,fsize
  378.     mov    [bx],ax
  379.     mov    ax,fsize+2
  380.     mov    [bx+2],ax
  381.  
  382.     mov    di,[bp+xfname]    ;dest string,
  383.     mov    si,offset dgroup:fname
  384.     mov    cx,12
  385.     cld
  386.     mov    ax,ds        ;set ES == DS,
  387.     mov    es,ax
  388. ;
  389. ;Fix a "slight" XENIX bug: Delete trailing 
  390. ;spaces, else it fails OPENs.
  391. ;
  392. xf2:    lodsb            ;get a byte,
  393.     cmp    al,0        ;if null
  394.     je    xf3
  395.     cmp    al,' '        ;or space,
  396.     je    xf3        ;stop,
  397.     stosb
  398.     loop    xf2        ;max 11 chars    
  399. xf3:    mov byte ptr [di],0    ;terminate,
  400.     mov    ax,1        ;good return.
  401. xfr:    pop    bp
  402.     ret
  403. _xfind endp
  404. page
  405. ;;
  406. ;;    fsize= _xfsize(filename)
  407. ;;    long fsize;
  408. ;;    char *filename;
  409. ;;
  410. ;;Return the size of a file, in bytes. Returns
  411. ;;0 if file not found. Filename can contain
  412. ;;a path.
  413. ;;
  414. ;;Cannot be called in between any _XFIND calls.
  415. ;;
  416. _xfsize proc near
  417.     push    bp
  418.     mov    bp,sp
  419.     mov    ah,26        ;set DMA addr
  420.     mov    dx,offset dgroup:xfbuf
  421.     int    21h        ;to buffer,
  422.     mov    ah,78        ;search 1st,
  423. xs1:    mov    dx,[bp+4]    ;path name,
  424.     mov    cx,0
  425.     int    21h
  426.     mov    ax,0        ;ret if no
  427.     mov    bx,0        ;match,
  428.     jc    xsr
  429.  
  430.     mov    bx,fsize
  431.     mov    ax,fsize+2
  432. xsr:    pop    bp
  433.     ret
  434. _xfsize endp
  435. page
  436. ;
  437. ;error= _xdelete(path);        OR    ERROR = _XUNLINK(PATH);
  438. ;int error;        0 IF SUCCESSFUL; -1 IF ERROR
  439. ;char *path;
  440. ;
  441. _XUNLINK PROC NEAR
  442. _xdelete proc near
  443.     push    bp
  444.     mov    bp,sp
  445.     mov    dx,[bp+4]
  446.     mov    ah,41h
  447.     int    21h
  448.     mov    ax,0
  449.     JNC    UNLKGR
  450.     DEC    AX
  451. UNLKGR:    pop    bp
  452.     ret
  453. _xdelete endp
  454. _XUNLINK ENDP
  455.  
  456. prog ends
  457. page
  458. data segment word public 'data'
  459. ;
  460. ;Structure for the FindFirst and FindNext
  461. ;function XFIND. NOT REENTRANT.
  462. ;
  463. xfbuf    db    (?)    ;search attrib
  464.     db    (?)    ;drive,
  465.     db 11 dup (?)    ;name,
  466.     dw    (?)    ;last ent
  467.     dd    (?)    ;DPB,
  468.     dw    (?)    ;dir start
  469.  
  470.     db    (?)    ;attrib found,
  471.     dw    (?)    ;time?
  472.     dw    (?)    ;date?
  473. fsize    dw    (?)    ;size low
  474.     dw    (?)    ;size hi,
  475. fname    db 13 dup (?)    ;packed name,
  476.  
  477. data ends    
  478.  
  479.     end
  480.